//
//  JrdCourseChpaterCellTableViewCell.m
//  v2ex-iOS
//
//  Created by longcheng on 16/5/21.
//  Copyright © 2016年 Singro. All rights reserved.
//

#import "JrdCourseNodeCellTableViewCell.h"
#import "JrdCommon.h"
#import "JrdNodeModel.h"
#import "JrdChapterModel.h"
@interface JrdCourseNodeCellTableViewCell(){
    UIImageView *_imageView;
    UIView* backgroundView;
    UILabel *_classNameLabel;/**< 课程名 */
    UILabel *_classHourseLabel;/**< 课程时长 */
}
@property (nonatomic, strong) JrdNodeModel* chapterModel;
@property (nonatomic, strong) JrdChapterModel* chapterModelExt;

@end
@implementation JrdCourseNodeCellTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(16, 0, 1, 64)];
        lineView.backgroundColor = JRD_RGB(219, 52, 50);
        [self.contentView addSubview:lineView];
        
        _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(9, 24, 16, 16)];
        _imageView.image = [UIImage imageNamed:@"bullet"];
        [self.contentView addSubview:_imageView];
        backgroundView = [[UIView alloc] initWithFrame:CGRectMake(40, 62, 0, 2)];
        backgroundView.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:backgroundView];
        //课程名
        _classNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 5, SCREEN_WIDTH-60, 30)];
        _classNameLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:_classNameLabel];
        //课程时长
        _classHourseLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 30, SCREEN_WIDTH-10-50, 30)];
        _classHourseLabel.textColor = [UIColor lightGrayColor];
        _classHourseLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_classHourseLabel];
        
        self.taskProgress = [[UIProgressView alloc] initWithFrame:CGRectMake(50, (64 - 7), SCREEN_WIDTH - 50 - 60, 5)];
        self.taskProgress.hidden = YES;
        [self.contentView addSubview:self.taskProgress];
        self.taskProgressLabel = [[UILabel alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 45), (64 - 20), 40, 20)];
        self.taskProgressLabel.text = @"20%";
        self.taskProgressLabel.hidden= YES;
        [self.taskProgressLabel setFont:[UIFont systemFontOfSize:12.f]];
        [self.contentView addSubview:self.taskProgressLabel];

    }
    return self;
}


-(void)setJzClassM:(JrdNodeModel *)jzClassM{
    _chapterModel = jzClassM;
    //NSLog(@"zlwu add for setJzClassM, name = %@ , level_id =%@",jzClassM.NodeName,jzClassM.NodeLevelId);
    if(0!= [jzClassM.NodeLevelId intValue]){
        _classNameLabel.text = [NSString stringWithFormat:@"%@",jzClassM.NodeName];
       [_classNameLabel setOrigin:CGPointMake(50, 5)];
//_classHourseLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 30, SCREEN_WIDTH-10-50, 30)];
        if(0==jzClassM.NodeDuration){
            _classHourseLabel.text = [NSString stringWithFormat:@"已学: 0%%"];
        }else{
            int study_pre = jzClassM.NodeStudyLength*100/jzClassM.NodeDuration;
            _classHourseLabel.text = [NSString stringWithFormat:@"已学: %d%%",study_pre];
            [backgroundView setSize:CGSizeMake((SCREEN_WIDTH-50)*study_pre/100, 2)];
        }
        //[_classHourseLabel setEnabled:YES];
    }else{
        _classNameLabel.text = [NSString stringWithFormat:@"%@",jzClassM.NodeName];
        [_classNameLabel setFrame:CGRectMake(50, (64-30)/2, SCREEN_WIDTH-60, 30)];
        //[_classHourseLabel setEnabled:NO];
        _classHourseLabel.text=@"";
    }
}

-(void)setJzClassM:(JrdNodeModel *)jzClassM isShowDownload:(BOOL)is_show_download{
    _chapterModel = jzClassM;
    if(true == is_show_download){
        [_classNameLabel setSize:CGSizeMake(SCREEN_WIDTH-100, 30)];
    }
    if(0!= [jzClassM.NodeLevelId intValue]){
        _classNameLabel.text = [NSString stringWithFormat:@"%@",jzClassM.NodeName];
        [_classNameLabel setOrigin:CGPointMake(50, 5)];
        //_classHourseLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 30, SCREEN_WIDTH-10-50, 30)];
        if(0==jzClassM.NodeDuration){
            _classHourseLabel.text = [NSString stringWithFormat:@"已学: 0%%"];
        }else{
            int study_pre = jzClassM.NodeStudyLength*100/jzClassM.NodeDuration;
            _classHourseLabel.text = [NSString stringWithFormat:@"已学: %d%%",study_pre];
            [backgroundView setSize:CGSizeMake((SCREEN_WIDTH-50)*study_pre/100, 2)];
        }
        //[_classHourseLabel setEnabled:YES];
    }else{
        _classNameLabel.text = [NSString stringWithFormat:@"%@",jzClassM.NodeName];
        [_classNameLabel setFrame:CGRectMake(50, (64-30)/2, SCREEN_WIDTH-60, 30)];
        //[_classHourseLabel setEnabled:NO];
        _classHourseLabel.text=@"";
    }
}


-(void)setJzClassMExt:(JrdChapterModel *)jzClassM{
    _chapterModelExt = jzClassM;
    _classNameLabel.text = [NSString stringWithFormat:@"第%@章:%@",jzClassM.ChapterIndex,jzClassM.ChapterName];
    
    //int length = [jzClassM.NodeDuration intValue];
    _classHourseLabel.text = [NSString stringWithFormat:@"课时%@", jzClassM.ChapterNodeNum];
}

@end
